package com.tan.simpleweather.base

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import com.tan.simpleweather.base.PlaceBean
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.PagerAdapter

class BasePagerAdapter(
    fm: FragmentManager?,
    private var fragmentList: List<Fragment>,
    private var listCities: List<PlaceBean>
) : FragmentPagerAdapter(fm!!) {
    override fun getItem(position: Int): Fragment {
        return fragmentList[position]
    }

    override fun getCount(): Int {
        return listCities.size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return listCities[position].name
    }

    override fun getItemPosition(obj: Any): Int {
        return POSITION_NONE
    }

    fun recreateItems(fragmentList: List<Fragment>, placeList: List<PlaceBean>) {
        this.fragmentList = fragmentList
        listCities = placeList
        notifyDataSetChanged()
    }
}